//
//  XS_RootVC.swift
//  EKLWisdomP3
//
//  Created by 韩云智 on 2020/10/16.
//

import Toast_Swift
import RxSwift
import RxCocoa

class XS_RootVC: XS_BaseVC {
    static let shared = XS_RootVC()
    override func upConfig() {
        ToastManager.shared.isQueueEnabled = true
        ToastManager.shared.style.messageAlignment = .center
    }
    override func upView() {
        _ = CGFloat.barHeight
        _ = CGFloat.bottomHeight
        XS_Singleton.shared.currentNetReachability()
        let version = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "0"
        
        if version == UserDefaults.standard.string(forKey: .xsKey_currentVersion) {
            
        } else {
            UserDefaults.standard.set(version, forKey: .xsKey_currentVersion)
        }
        
//        _ = Observable<Int>.interval(.seconds(60), scheduler: MainScheduler.asyncInstance)
//            .subscribe(onNext: { _ in
//                guard XS_Singleton.shared.infoModel != nil else { return }
//                _ = XS_NetWork.requestJson("/plan/uploadUserLearnTime", parameters: ["time": "1"])
//                    .subscribe()
//            })
        
        
//        if let data = UIImage(named: "矩形备份 9")?.jpegData(compressionQuality: 0.1) { // 上传文件
//            XS_NetWork.xs_uploadFile(XS_NetWork.XS_UploadM(data: data)) { resp in
//                print(resp?.msg)
//                print(resp?.data)
//            }
//        }
        
        
        
//        XS_NetWork.requestJson("/user/getCurrUser")
//            .subscribe(onNext: { resp in //直接返回原始数据 resp.data
//                print(resp.msg)
//            }).disposed(by: disposeBag)
//
//        XS_NetWork.requestJson("/user/getCurrUser")
//            .mapModels(type: XS_UserBOM.self) // 返回 模型数组 和原始数据
//            .subscribe(onNext: { array, resp in
//                print(resp.msg)
//            }).disposed(by: disposeBag)
//
//        XS_NetWork.requestJson("/user/getCurrUser")
//            .mapModel(type: XS_UserBOM.self) // 返回 模型对象 和原始数据
//            .subscribe(onNext: { model, resp in
//                print(resp.msg)
//            }).disposed(by: disposeBag)
        
//        XS_NetWork.requestJson("/user/getCurrUser")
//            .subscribe() // 不做处理的请求
//            .disposed(by: disposeBag) // 请求 随 disposeBag 销毁而 销毁
        
//        _ = XS_NetWork.requestJson("/user/getCurrUser") // 不考虑销毁的 请求
//            .subscribe()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let vc = XS_NVC.shared
        vc.setNavigationBarHidden(true, animated: false)
        vc.modalTransitionStyle = .crossDissolve
        present(vc, animated: false)
        if XS_Singleton.shared.infoModel == nil {
            vc.pushViewController(XS_LoginVC(), animated: false)
        } else {
            XS_NetWork.requestJson("/user/getCurrUser")
                .mapModel(type: XS_UserBOM.self)
                .subscribe(onNext: { model, resp in
                    guard resp.success, let model = model else {
                        vc.pushViewController(XS_LoginVC(), animated: false)
                        return
                    }
                    XS_Singleton.shared.infoModel?.userBO = model
                    if XS_Singleton.shared.infoModel?.isAnswer == 0 {
                        let qvc = XS_Q1VC()
                        qvc.title = "问题1，共3"
                        qvc.text = "您的就业方向是什么？"
                        qvc.desc = "请回答下列问题，方便我们为您量身定制课程计划。"
                        vc.pushViewController(qvc, animated: true)
                    }
                }).disposed(by: disposeBag)
        }
    }
    
}
